function tailleMinimale(champ, taille) {
	var alerte = document.getElementById(champ.name);
	if(champ.value.length < taille) {
		alerte.style.display = "block";
		alerte.style.color = "red";
		alerte.style.fontSize = "0.7em";
		champ.style.border = "2px solid red";
	} else {
		alerte.style.display = "none";
		champ.style.border = "2px solid green";
	}
}	

function compareMDP(champ) {
	var alerte = document.getElementById(champ.name);
	var mdp_initial = document.getElementById('mdp_initial');
	if(champ.value == mdp_initial.value) {
		alerte.style.display = "none";
		champ.style.border = "2px solid green";
	} else {
		alerte.style.display = "block";
		alerte.style.color = "red";
		alerte.style.fontSize = "0.7em";
		champ.style.border = "2px solid red";		
	}
}

function verifieTel(champ) {
	var alerte = document.getElementById(champ.name);
	var telephone = champ.value;
	var regex1 = /^0\d[-_/\. ](\d\d[-_/\. ]){3}\d\d$/;
	var regex2 = /^0\d(\d\d){4}$/;
	if(regex1.test(telephone) || regex2.test(telephone)) {
  		alerte.style.display = "none";
		champ.style.border = "2px solid green";
	} else {
  		alerte.style.display = "block";
		alerte.style.color = "red";
		alerte.style.fontSize = "0.7em";
		champ.style.border = "2px solid red";
	}
}

function verifieMail(champ) {
	var alerte = document.getElementById(champ.name);
	var mail = champ.value;
	var regex = /^[a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,6}$/;
	if(regex.test(mail)) {
  		alerte.style.display = "none";
		champ.style.border = "2px solid green";
	} else {
  		alerte.style.display = "block";
		alerte.style.color = "red";
		alerte.style.fontSize = "0.7em";
		champ.style.border = "2px solid red";
	}
}

function verifieCP(champ) {
	var alerte = document.getElementById(champ.name);
	var CP = champ.value;
	var regex = /^(\d){5}$/;
	if(regex.test(CP)) {
  		alerte.style.display = "none";
		champ.style.border = "2px solid green";
	} else {
  		alerte.style.display = "block";
		alerte.style.color = "red";
		alerte.style.fontSize = "0.7em";
		champ.style.border = "2px solid red";
	}
}

function verifieWeb(champ) {
	var alerte = document.getElementById(champ.name);
	var web = champ.value;
	var regex = /^(http\:\/\/|https\:\/\/)+([a-z0-9][a-z0-9\-]*\.)+[a-z0-9][a-z0-9\-]*$/;
	if(regex.test(web)) {
  		alerte.style.display = "none";
		champ.style.border = "2px solid green";
	} else {
  		alerte.style.display = "block";
		alerte.style.color = "red";
		alerte.style.fontSize = "0.7em";
		champ.style.border = "2px solid red";
	}
}

function connexionXMLDoc(page) {
	if(window.XMLHttpRequest) {//Code pour IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	} else {//Code pour IE6 et IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.open("GET", page, false); 
    xmlhttp.send(null);
    if(xmlhttp.readyState == 4) {
    	return xmlhttp.responseText;
    }
}

function pseudoValide(champ) {
	var pseudo = champ.value;
	var alerte = document.getElementById('pseudo');
	if(pseudo != "") {
		if(pseudo.length < 5) {
			alerte.style.display = "block";
			alerte.style.color = "red";
			alerte.style.fontSize = "0.7em";
			champ.style.border = "2px solid red";
			alerte.innerHTML = " Pseudo trop court ";			
		} else if(reponse = connexionXMLDoc('http://localhost/APP%20Informatique_GC/Modele/pseudo_libre.php?pseudo='+pseudo)) {
			if(reponse == "non libre") {
				alerte.style.display = "block";
				alerte.style.color = "red";
				alerte.style.fontSize = "0.7em";
				champ.style.border = "2px solid red";
				alerte.innerHTML = " Pseudo non disponible ";
			} else {
				alerte.style.display = "none";
				champ.style.border = "2px solid green";
			}
		}
	}
}